<template>
  <el-dialog
    :title="!this.dataForm.rdUuid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm"  label-width="80px">
    <el-form-item label="用户id" prop="rdUrId">
      <el-input v-model="dataForm.rdUrId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="充值金额" prop="rdPrice">
      <el-input v-model="dataForm.rdPrice" placeholder="充值金额"></el-input>
    </el-form-item>
    <el-form-item label="订单创建时间" prop="rdCreateTime">
      <el-input v-model="dataForm.rdCreateTime" placeholder="订单创建时间"></el-input>
    </el-form-item>
    <el-form-item label="充值状态" prop="rdStatus">
      <el-input v-model="dataForm.rdStatus" placeholder="充值状态"></el-input>
    </el-form-item>
    <el-form-item label="充值过后的金额变动余额" prop="rdCountPrice">
      <el-input v-model="dataForm.rdCountPrice" placeholder="充值过后的金额变动余额"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import api from "@/api/modules/cddrechargedetails";
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          rdUuid: 0,
          rdUrId: '',
          rdPrice: '',
          rdCreateTime: '',
          rdStatus: '',
          rdCountPrice: ''
        },
        dataRule: {
          rdUrId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          rdPrice: [
            { required: true, message: '充值金额不能为空', trigger: 'blur' }
          ],
          rdCreateTime: [
            { required: true, message: '订单创建时间不能为空', trigger: 'blur' }
          ],
          rdStatus: [
            { required: true, message: '充值状态不能为空', trigger: 'blur' }
          ],
          rdCountPrice: [
            { required: true, message: '充值过后的金额变动余额不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.rdUuid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          api.info(this.dataForm.rdUuid).then(({data}) => {
              if (data) {
                this.dataForm.rdUrId = data.cddRechargeDetails.rdUrId
                this.dataForm.rdPrice = data.cddRechargeDetails.rdPrice
                this.dataForm.rdCreateTime = data.cddRechargeDetails.rdCreateTime
                this.dataForm.rdStatus = data.cddRechargeDetails.rdStatus
                this.dataForm.rdCountPrice = data.cddRechargeDetails.rdCountPrice
              }
            })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
    var parms= {
'rdUuid': this.dataForm.rdUuid || undefined,
'rdUrId': this.dataForm.rdUrId,
'rdPrice': this.dataForm.rdPrice,
'rdCreateTime': this.dataForm.rdCreateTime,
'rdStatus': this.dataForm.rdStatus,
'rdCountPrice': this.dataForm.rdCountPrice        }
        api.updateAdd(parms,this.dataForm.rdUuid).then((res) => {
              if (res.code==200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
